package com.ybf.user.dal.manager;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ybf.user.dal.entity.AdminRoleDO;
import com.ybf.user.dal.mapper.AdminRoleMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.Collections;
import java.util.List;
import java.util.Objects;

/**
 * @Date
 * @Author
 **/
@Component
public class AdminRoleManager extends ServiceImpl<AdminRoleMapper, AdminRoleDO> {

    @Autowired
    private AdminRoleMapper adminRoleMapper;

    /**
     * 列表 by admin id
     *
     * @author 向南
     * @date 15:01 2023/7/7
     * @param: adminId
     **/
    public List<AdminRoleDO> selectByAdminId(Long adminId) {
        if(Objects.isNull(adminId)) {
            return Collections.emptyList();
        }
        return adminRoleMapper.selectList(new LambdaUpdateWrapper<AdminRoleDO>().eq(AdminRoleDO::getAdminId, adminId));
    }

    /**
     *
     *
     * @author 向南
     * @date 11:36 2023/7/28
     * @param: collect
     **/
    public List<AdminRoleDO> selectInAdminIds(List<Long> adminIds) {
        if (CollectionUtils.isEmpty(adminIds)) {
            return Collections.emptyList();
        }
        return adminRoleMapper.selectList(new LambdaQueryWrapper<AdminRoleDO>().in(AdminRoleDO::getAdminId, adminIds));
    }

    /**
     *
     *
     * @author 向南
     * @date 17:30 2023/7/31
     * @param: id
     **/
    public List<AdminRoleDO> selectByRoleId(Long roleId) {
        if (Objects.isNull(roleId)) {
            return Collections.emptyList();
        }
        return adminRoleMapper.selectList(new LambdaQueryWrapper<AdminRoleDO>().in(AdminRoleDO::getRoleId, roleId));
    }
}
